package com.cqcetbbs.smartlab.cqcetbbs.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.Toast;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.radar.RadarNearbyResult;
import com.baidu.mapapi.radar.RadarSearchError;
import com.baidu.mapapi.radar.RadarSearchListener;
import com.baidu.mapapi.radar.RadarSearchManager;
import com.cqcetbbs.smartlab.cqcetbbs.R;

/**
 * Created by user on 2017/10/23.
 * 校园导航
 */

public class MapActivity extends Activity implements RadarSearchListener {

    private MapView mMapView = null;
    private BaiduMap mBaiduMap;
    RadarSearchManager mManager;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //在使用SDK各组件之前初始化context信息，传入ApplicationContext
        //注意该方法要再setContentView方法之前实现
        setContentView(R.layout.activity_map);
        mMapView = findViewById(R.id.mMapView);

        mBaiduMap = mMapView.getMap();
        mBaiduMap.setIndoorEnable(true); // 打开室内图
        mManager = RadarSearchManager.getInstance();

    }




    @Override
    protected void onDestroy() {
        super.onDestroy();
        //在activity执行onDestroy时执行mMapView.onDestroy()，实现地图生命周期管理
        mMapView.onDestroy();
        //移除监听
        mManager.removeNearbyInfoListener(this);
        //清除用户信息
        mManager.clearUserInfo();
        //释放资源
        mManager.destroy();
        mManager = null;
    }

    @Override
    protected void onResume() {
        super.onResume();
        //在activity执行onResume时执行mMapView. onResume ()，实现地图生命周期管理
        mMapView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        //在activity执行onPause时执行mMapView. onPause ()，实现地图生命周期管理
        mMapView.onPause();
    }

    @Override
    public void onGetNearbyInfoList(RadarNearbyResult radarNearbyResult, RadarSearchError radarSearchError) {

    }


    //监听上传结果
    @Override
    public void onGetUploadState(RadarSearchError radarSearchError) {
        Log.e("====================", "ccccccccccccccccccccc");
        if (radarSearchError == RadarSearchError.RADAR_NO_ERROR) {
            //上传成功
            Toast.makeText(MapActivity.this, "单次上传位置成功", Toast.LENGTH_LONG)
                    .show();
        } else {
            //上传失败
            Toast.makeText(MapActivity.this, "单次上传位置失败", Toast.LENGTH_LONG)
                    .show();
        }

    }

    @Override
    public void onGetClearInfoState(RadarSearchError radarSearchError) {

    }
}
